Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce dependency on web audio #190

Merged

Conversation

pendragon-andyh
Copy link
Contributor

@pendragon-andyh pendragon-andyh commented Jul 28, 2020

Fixes for:
. #145 (Initialize Without Web Audio Context)
. #147 (10% cpu usage by pulseaudio when a UI is loaded)

Notes:
. Need to regenerate api.json file.
. Need to update the NPM version numbers in the API index.html (or use @next?)

I have added pull-request comments so that you can more easily understand what I'm thinking.

Comment on lines -1594 to -1596
if (Nexus.context.close) {
Nexus.context.close();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the new Nexus.context causes an AudioContext to be created (see the new version of main.js).

@@ -28,45 +29,21 @@ import { context } from '../main';

export default class Meter extends Interface {
constructor() {
let options = ['scale', 'value'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scale and value don't seem to be used in Meter, Oscilloscope, and Spectrogram. Smells like copy-and-paste.

@@ -142,46 +119,59 @@ export default class Meter extends Interface {
}

/**
Equivalent to "patching in" an audio node to visualize. NOTE: You cannot connect audio nodes across two different audio contexts. NexusUI runs its audio analysis on its own audio context, Nexus.context. If the audio node you are visualizing is created on a different audio context, you will need to tell NexusUI to use that context instead: i.e. Nexus.context = YourAudioContextName. For example, in ToneJS projects, the line would be: Nexus.context = Tone.context . We recommend that you write that line of code only once at the beginning of your project.
Copy link
Contributor Author

@pendragon-andyh pendragon-andyh Jul 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "NOTE" and the first line of the original example are no longer relevant.

Comment on lines -158 to +132
if (channels) {
this.channels = channels;
} else if (node.channelCount) {
this.channels = node.channelCount;
} else {
this.channels = 2;

this.channels = channels || node.channelCount || 2;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified

}

click() {
this.active = !this.active;
this.active = !this.active && this.source;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only toggle if the meter is connected to an AudioNode.

Comment on lines +20 to +37
function unlockAudioContext(audioContext) {
const events = ['touchstart', 'touchend', 'mousedown', 'keydown'];

function unlock() {
events.forEach((eventName) => document.body.removeEventListener(eventName, unlock));
if (audioContext.state === 'suspended') {
console.log('Audio context - unlocked ...');
audioContext.resume();
}
}

if (audioContext.state === 'suspended') {
console.log('Audio context - suspended until user interaction ...');
events.forEach(eventName => {
document.body.addEventListener(eventName, unlock, false);
});
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. Similar code seems to be used by multiple WebAudio projects (because AudioContext is supposed to initialize in a "suspended" state). Recent WebAudio issues indicate that this is implemented differently between the different browsers.


/**
NexusUI => created as Nexus
*/

class NexusUI {

constructor(context) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if reformatting was caused by editor or lint settings.

Comment on lines +140 to +141
this._clock = new WAAClock(this.context);
this._clock.start();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clock is only created (and started) when it is specifically requested. I didn't create a setter.

@pendragon-andyh pendragon-andyh marked this pull request as ready for review July 28, 2020 21:51
lazzarello added a commit to lazzarello/scarlett-18i8-mixer that referenced this pull request Aug 11, 2020
[Nexus UI Tutorial](https://nexus-js.github.io/ui/api/#intro), but for Vue.js with [async components](https://vuejs.org/v2/guide/components-dynamic-async.html#Async-Components) loading to enable the web audio context. The async stuff might not be needed when the [relevant PR is merged](nexus-js/ui#190).
@tatecarson tatecarson self-assigned this Aug 27, 2020
Copy link
Collaborator

@tatecarson tatecarson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for all the work.

@tatecarson tatecarson merged commit fc13997 into nexus-js:master Aug 29, 2020
tatecarson added a commit that referenced this pull request Aug 29, 2020
* updated discord message

* feat: support for vertical orientation (#115)

* fix: Nexus.tune.createScale() does not produce expected scale (#138)

* fix: numberOfSliders does not change number of sliders for Multislider (#161)

* feat: support for vertical orientation (#115)

* feat: add padding to sequencer (#150) #178

* feat: add padding to sequencer (#150) #178

* removed commented out line

* chore(release): 2.1.0

* chore(release): 2.1.1

* chore(release): 2.1.2

* add build

* fix issue #161

* modify regex to support input of negative numbers to number component

* update dist after regex change

* chore(release): 2.1.3

* 🐛 Fix Nexus.Interval import regression

* Fix Nexus.Interval import regression #184

* chore(release): 2.1.4

* Implement multi-touch piano

* chore(release): 2.1.5

* Remove document.write

* Rebuild dist files

* Fix broken CSS in examples

* Bump websocket-extensions from 0.1.3 to 0.1.4 (#185)

Bumps [websocket-extensions](https://github.com/faye/websocket-extensions-node) from 0.1.3 to 0.1.4.
- [Release notes](https://github.com/faye/websocket-extensions-node/releases)
- [Changelog](https://github.com/faye/websocket-extensions-node/blob/master/CHANGELOG.md)
- [Commits](faye/websocket-extensions-node@0.1.3...0.1.4)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump standard-version from 7.1.0 to 8.0.1 (#187)

Bumps [standard-version](https://github.com/conventional-changelog/standard-version) from 7.1.0 to 8.0.1.
- [Release notes](https://github.com/conventional-changelog/standard-version/releases)
- [Changelog](https://github.com/conventional-changelog/standard-version/blob/master/CHANGELOG.md)
- [Commits](conventional-changelog/standard-version@v7.1.0...v8.0.1)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Reduce dependency on web audio (#190)

* Only create AudioContext when necessary

* Tweak npm version

* Rebuild dist files

* update documention cdn to use latest build

* fixed mistake

* fixed main and build

* "chore(release): 2.1.6"

* Update index.html

trying to get it to rebuild

Co-authored-by: Vladan Sarac <[email protected]>
Co-authored-by: jamesstaub <[email protected]>
Co-authored-by: Theis Bazin <[email protected]>
Co-authored-by: Andy Harman <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Andy Harman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants